# -*- coding: utf-8 -*-
"""
Created on Sun Aug 22 15:53:13 2021

@author: xiong
"""
import os
import shutil
def file_name(file_dir):  
    L=[]
    name=[]
    for root, dirs, files in os.walk(file_dir): 
        for file in files: 
            if os.path.splitext(file)[1] == '.csv': 
                L.append(os.path.join(root, file))
                name.append(file)
    return L,name 


csvpath=r'E:\tutu\csv'#运行csv所在的文件夹，该程序运行的是该文件夹下的所有的csv文件
sp = r'E:\tutu\123' #目标路径


L,name=file_name(csvpath)

for i in range(len(L)):
    str5 = name[i]
    print(str5)
    if str5[-5:] == '计.csv':
        continue
    str5_1=str5.split('.')[1]#大地域编号
    str5_1='地域'+str5_1  #地域1
#########################################################

    str5_2_1=str5.split('.')[0]#温度带 5
    str5_3=str5.split('.')[2]#地域 0
    str5_4=str5.split('.')[3].split('_')[0]#子类型 5
    
    temprList = ['温度交错带','高山极地带', '苔原带', '寒温带', '中温带', '暖温带', '亚热带', '热带']
    

    tmix_list=[]
    tmix_str=''
    if str5_2_1 == '0':
        tmix=str5.split('_')[1][:-4]
        tmix_list=tmix.split('.')
        for TL in range(len(tmix_list)):
            tmix_list[TL]  = temprList[int(tmix_list[TL])]
        tmix_str='-'.join(tmix_list)
     
        sph = sp +'\\温度带' + '\\' +str5_2_1 + '_' + temprList[int(str5_2_1)] + '\\'  + tmix + '_' + tmix_str+'交错带' +  '\\csv'
        try:
            os.mkdir(sph)
        except:
            pass
        sph = sp +'\\温度带' + '\\' +str5_2_1 + '_' + temprList[int(str5_2_1)] + '\\' + tmix + '_' + tmix_str+'交错带' + '\\'   + '\\csv\\%s'
    else:
        sph = sp +'\\温度带' + '\\' +str5_2_1 + '_' + temprList[int(str5_2_1)] + '\\' + '\\csv'
        try:
            os.mkdir(sph)
        except:
            pass
        sph = sp +'\\温度带' + '\\' +str5_2_1 + '_' + temprList[int(str5_2_1)] + '\\'   + '\\csv\\%s'
    print(sph)
    shutil.move(L[i],sph%name[i])
    